package service

import (
	"math"
	"zimuzu_cvn_web_api/model"
	. "zimuzu_cvn_web_api/pkg/e"
)

//校验流水正负号
func CheckCvnLogSourceSymbol(source int, amount, frozenAmount float64) bool {
	if ContainInt(model.CvnLogSourceAmountInc, source) {
		if amount < 0 {
			return false
		}
	} else if ContainInt(model.CvnLogSourceAmountDec, source) {
		if amount > 0 {
			return false
		}
	}
	if ContainInt(model.CvnLogSourceFrozenAmountInc, source) {
		if frozenAmount < 0 {
			return false
		}
	} else if ContainInt(model.CvnLogSourceFrozenAmountDec, source) {
		if frozenAmount > 0 {
			return false
		}
	}
	if math.Abs(amount) > 0 && math.Abs(frozenAmount) > 0 {
		if math.Abs(amount) != math.Abs(frozenAmount) {
			return false
		}
	}
	return true
}

func ExamineCvnLogSourceSymbol(source int, amount float64) bool {
	if ContainInt(model.CvnLogSourceAmountInc, source) {
		if amount < 0 {
			return false
		}
	} else if ContainInt(model.CvnLogSourceAmountDec, source) {
		if amount > 0 {
			return false
		}
	} else {
		return false
	}
	return true
}
